package com.shop.mapper;

import com.shop.dto.InvoiceDTO;
import com.shop.dto.OrderItem;
import com.shop.model.Invocei;
import com.shop.model.Order;
import lombok.Data;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrderMapper {
    // 插入订单
//    int insert(Order order);

    // 根据订单编号查询订单
    @Select("select *from `order` where no=#{orderNo}")
    Order selectByOrderNo(String orderNo);
    @Select("SELECT *from `order` where id=#{id}")
    Order selectById(Integer id);

    // 根据用户ID查询订单列表
    @Select("SELECT *from `order` where user_id=#{userId}")
    List<Order> selectByUserId(Integer userId);

    // 更新订单状态
    int updateStatus(String orderNo, String status, Date payTime);

    // 删除订单
    int deleteByOrderNo(Integer id);

    // 查询所有订单
    List<Order> selectAllOrders();

    // 根据条件查询订单
//    List<Order> selectByCondition(String orderNo, Integer userId, String status);

    // 插入订单
//    @Insert("INSERT INTO orders (no, add_time, user_id, total_money, address, accept, telphone, pay_type, status) VALUES (#{no}, #{addTime}, #{userId}, #{totalMoney}, #{address}, #{accept}, #{telphone}, #{payType}, #{status})")
//    int insertOrder(Order order);
    @Insert("INSERT INTO `order` (goodid,add_time, user_id, total_money, address, telphone, pay_type, status,no) VALUES (#{goodid}, #{addTime}, #{userId}, #{totalMoney}, #{address}, #{telphone}, #{payType}, #{status},#{no})")
    int addOrderInfo(Order order);

    // 插入订单项
    @Insert("INSERT INTO order_item (order_id, goods_id, name, image, price, num) VALUES (#{orderId}, #{goodsId}, #{name}, #{image}, #{price}, #{num})")
    int insertOrderItem(OrderItem orderItem);

    void updateOrderStutus(String outTradeNo, Integer userId);


    InvoiceDTO selectInvoiceDTO(Integer orderId);

    void addInvoice(Invocei invocei);

    Invocei getInvoice(Integer id);

    Invocei getInvoiceByOrderId(int orderId);
}